package com.ruoyi.basebill.controller;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.basebill.domain.BomCostcalc;
import com.ruoyi.basebill.service.IBomCalcdemandService;
import com.ruoyi.basebill.service.IBomCostcalcService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basebill.domain.BomCalcdemand;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测试需求单维护Controller
 * 
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/bomcostestimation/basebill/calcdemand")
public class BomCalcdemandController extends BaseController
{
    @Autowired
    private IBomCalcdemandService bomCalcdemandService;
    @Autowired
    private IBomCostcalcService bomCostcalcService;
    /**
     * 查询测试需求单维护列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:list')")
    @GetMapping("/list")
    public TableDataInfo list(BomCalcdemand bomCalcdemand)
    {
        startPage();
        List<BomCalcdemand> list = bomCalcdemandService.selectBomCalcdemandList(bomCalcdemand);
        return getDataTable(list);
    }

    /**
     * 导出测试需求单维护列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:export')")
    @Log(title = "测试需求单维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomCalcdemand bomCalcdemand)
    {
        List<BomCalcdemand> list = bomCalcdemandService.selectBomCalcdemandList(bomCalcdemand);
        ExcelUtil<BomCalcdemand> util = new ExcelUtil<BomCalcdemand>(BomCalcdemand.class);
        util.exportExcel(response, list, "测试需求单维护数据");
    }

    /**
     * 获取测试需求单维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:query')")
    @GetMapping(value = "/{fid}")
    public AjaxResult getInfo(@PathVariable("fid") String fid)
    {
        return success(bomCalcdemandService.selectBomCalcdemandByFid(fid));
    }

    /**
     * 新增测试需求单维护
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:add')")
    @Log(title = "测试需求单维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BomCalcdemand bomCalcdemand)
    {
        return toAjax(bomCalcdemandService.insertBomCalcdemand(bomCalcdemand));
    }

    /**
     * 修改测试需求单维护
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:edit')")
    @Log(title = "测试需求单维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BomCalcdemand bomCalcdemand)
    {
        return toAjax(bomCalcdemandService.updateBomCalcdemand(bomCalcdemand));
    }

    /**
     * 删除测试需求单维护
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:remove')")
    @Log(title = "测试需求单维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fids}")
    public AjaxResult remove(@PathVariable String[] fids)
    {
        return toAjax(bomCalcdemandService.deleteBomCalcdemandByFids(fids));
    }
    /**
     * 测试需求单维护下推成本测算
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:push')")
    @Log(title = "测试需求单维护", businessType = BusinessType.OTHER)
    @PostMapping("/push")
    public AjaxResult pushCostCalc(@RequestBody String[] fids)
    {
        return toAjax(bomCalcdemandService.pushCostCalc(fids));
    }

    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:checkBelow')")
    @Log(title = "测试需求单维护", businessType = BusinessType.OTHER)
    @PostMapping("/checkBelow")
    public AjaxResult checkBelow(@RequestBody String fid) {
        return success(bomCostcalcService.selectBomCostcalcByCalcDemandfid(fid));
    }

    /**
     * 单据状态操作
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basebill:calcdemand:aduit')")
    @GetMapping("/optionstatus/{ids}/{status}")
    public HashMap optionStatus(@PathVariable String[] ids, @PathVariable String status) {
        HashMap hashMap = bomCalcdemandService.optionStatus(ids, status);
        return hashMap;
    }
}
